﻿namespace CityProvince.Store;

public static class ConstantCollections {
    /// <summary>
    /// DataLoadedCompleted
    /// </summary>
    /// <remarks>
    /// Running on UI Thread
    /// </remarks>
    public static event EventHandler? DataLoadedCompleted;
    public static IReadOnlyDictionary<string, string> CityProvinceDict { get; private set; } = null!;
    public static IReadOnlyList<string> Provinces { get; private set; } = null!;
    public static bool IsDataLoadedCompleted { get; private set; }

    static ConstantCollections() {
        Task.Run(() => {
            Provinces = Resources.Resources.Provinces.Split('\n', StringSplitOptions.TrimEntries | StringSplitOptions.RemoveEmptyEntries);
            CityProvinceDict = JsonSerializer.Deserialize<Dictionary<string, string>>(
                Encoding.UTF8.GetString(Resources.Resources.Cities)
            )!;
            UIUtils.RunOnUIThread(() => {
                IsDataLoadedCompleted = true;
                DataLoadedCompleted?.Invoke(null, new());
            });
        });
    }
}
